package com.haoxi.gateway.cmppmsg;

import com.haoxi.gateway.util.TypeConvert;

public class CMPP30DeliverRepMessage extends CMPPMessage {

    private StringBuffer outBuf;

    public CMPP30DeliverRepMessage(byte msg_Id[], int result)
            throws IllegalArgumentException {
        if (msg_Id.length > 8)
            throw new IllegalArgumentException(
                    "The parameter of deliver response message is wrong:msg_Id length is larger than 8");

        if (result < 0 || result > 0x7fff) {
            throw new IllegalArgumentException(
                    "The parameter of deliver response message is wrong:result less than 0 or larger than 32767.");
        } else {
            int len = 24;
            buf = new byte[len];
            TypeConvert.int2byte(len, buf, 0);
            TypeConvert.int2byte(CMPPCommon.CMPP_DELIVER_RESP, buf, 4);
            System.arraycopy(msg_Id, 0, buf, 12, msg_Id.length);
            TypeConvert.int2byte(result, buf, 20);
            outBuf=new StringBuffer();
            outBuf.append(",msgid=").append(CMPPCommon.getMsgIdStr(msg_Id));
            outBuf.append(",result=").append(result);
     
        }
    }

    public String toString() {
        StringBuffer tmpBuf = new StringBuffer("CMPP_Deliver_REP: ");
        tmpBuf.append("Sequence_Id=").append(getSequenceId());
        tmpBuf.append(outBuf.toString());
        return tmpBuf.toString();
    }

    public int getCommandId() {
        return CMPPCommon.CMPP_DELIVER_RESP;
    }
}
